layui.use(['form','jquery','jquery_cookie'], function () {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery,
        $ = layui.jquery_cookie($);

    form.on("submit(login)",function (data) {
        // console.log(data);

         $.ajax({
           url: ctx+"/user/login",
           data: {
               userName: data.field.username,
               password: data.field.password
           },
            type: "POST",
            success:function(res){
                // console.log(res)
                if (res.code==200){
                    // 设置cookie信息
                    $.cookie("userIdStr",res.result.userIdStr);
                    $.cookie("trueName",res.result.trueName);
                    $.cookie("userName",res.result.userName);

                    // 登入成功
                    window.location = ctx+"/main";

                }else{
                    layer.alert(res.msg,{icon:5});
                }
            }
         })

        return false;
    })
});